package com.tushikeji.facecar.utils;

import android.content.Context;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.util.Log;

import java.io.IOException;

public class PlayConfBell {
    private final static String TAG = "PlayConfBell";
    private static MediaPlayer player;

    public static boolean playBell(Context context, int id) {
     //   Zlog.Log("走到了  playBell");
        player = MediaPlayer.create(context, id);
        player.setOnCompletionListener(new OnCompletionListener() {

            @Override
            public void onCompletion(MediaPlayer mp) {
                // TODO Auto-generated method stub
          //      Zlog.Log("走到了 onCompletion");
                mp.release();
            }
        });
        try {
            if (player != null) {
                player.stop();
            }
            player.prepare();
            player.start();
        } catch (IllegalStateException e) {
            player.release();
            Log.e(TAG, e.getMessage());
        //    Zlog.Log("走到了 IllegalStateException");
            return false;
        } catch (IOException e) {
            player.release();
            Log.e(TAG, e.getMessage());
        //    Zlog.Log("走到了 IOException");
            return false;
        }
        return true;
    }
}